home *** CD-ROM | disk | FTP | other *** search
/ C++ für Kids / C++ for kids.iso / SETUP / US / CBUILDER / DATA.Z / IOSTREAM.H < prev    next >
C/C++ Source or Header  |  1997-02-13  |  36KB  |  872 lines

  1. /*  iostream.h -- basic stream I/O declarations
  2.  
  3.     There are some inline functions here which generate a LOT of code
  4.     (as much as 300 bytes), but are available inline because AT&T did
  5.     it that way.  We have also made them true functions in the library
  6.     and conditionally deleted the inline code from this header.
  7.  
  8.     If you really want these big functions to be inline, #define the
  9.     macro name _BIG_INLINE_ before including this header.
  10.  
  11.     Programs will compile and link correctly even if some modules are
  12.     compiled with _BIG_INLINE_ and some are not.
  13. */
  14.  
  15. /*
  16.  *      C/C++ Run Time Library - Version 8.0
  17.  *
  18.  *      Copyright (c) 1990, 1997 by Borland International
  19.  *      All Rights Reserved.
  20.  *
  21.  */
  22. /* $Revision:   8.6  $ */
  23.  
  24. #ifndef __cplusplus
  25. #error Must use C++ for the type iostream.
  26. #endif
  27.  
  28. #ifndef __IOSTREAM_H
  29. #define __IOSTREAM_H
  30.  
  31. #if !defined(___DEFS_H)
  32. #include <_defs.h>
  33. #endif
  34.  
  35. #if !defined(__STRING_H)
  36. #include <string.h>    // to get strnicmp, memcpy and NULL
  37. #endif
  38.  
  39.  
  40. #if !defined(RC_INVOKED)
  41.  
  42. #pragma pack(push, 1)
  43.  
  44. #if defined(__BCOPT__)
  45. #if !defined(_RTL_ALLOW_po) && !defined(__FLAT__)
  46. #pragma option -po-     // disable Object data calling convention
  47. #endif
  48. #endif
  49.  
  50. #if !defined(__TINY__)
  51. #pragma option -RT
  52. #endif
  53.  
  54. #pragma option -Vo-     // set standard C++ options
  55.  
  56. #if defined(__STDC__)
  57. #pragma warn -nak
  58. #endif
  59.  
  60. #endif  /* !RC_INVOKED */
  61.  
  62.  
  63. // Definition of EOF must match the one in <stdio.h>
  64. #define EOF (-1)
  65.  
  66. // extract a char from int i, ensuring that zapeof(EOF) != EOF
  67. #define zapeof(i) ((unsigned char)(i))
  68.  
  69. typedef long streampos;
  70. typedef long streamoff;
  71.  
  72. _CLASSDEF(ios)
  73. _CLASSDEF(streambuf)
  74. _CLASSDEF(istream)
  75. _CLASSDEF(ostream)
  76. _CLASSDEF(iostream)
  77. _CLASSDEF(istream_withassign)
  78. _CLASSDEF(ostream_withassign)
  79. _CLASSDEF(iostream_withassign)
  80.  
  81. class _EXPCLASS ios {
  82. public:
  83.     // stream status bits
  84.     enum io_state   {
  85.         goodbit  = 0x00,    // no bit set: all is ok
  86.         eofbit   = 0x01,    // at end of file
  87.         failbit  = 0x02,    // last I/O operation failed
  88.         badbit   = 0x04,    // invalid operation attempted
  89.         hardfail = 0x80     // unrecoverable error
  90.         };
  91.  
  92.     // stream operation mode
  93.     enum open_mode  {
  94.         in   = 0x01,        // open for reading
  95.         out  = 0x02,        // open for writing
  96.         ate  = 0x04,        // seek to eof upon original open
  97.         app  = 0x08,        // append mode: all additions at eof
  98.         trunc    = 0x10,    // truncate file if already exists
  99.         nocreate = 0x20,    // open fails if file doesn't exist
  100.         noreplace= 0x40,    // open fails if file already exists
  101.         binary   = 0x80     // binary (not text) file
  102.         };
  103.  
  104.     // stream seek direction
  105.     enum seek_dir { beg=0, cur=1, end=2 };
  106.  
  107.     // formatting flags
  108.     enum    {
  109.         skipws    = 0x0001, // skip whitespace on input
  110.         left      = 0x0002, // left-adjust output
  111.         right     = 0x0004, // right-adjust output
  112.         internal  = 0x0008, // padding after sign or base indicator
  113.         dec       = 0x0010, // decimal conversion
  114.         oct       = 0x0020, // octal conversion
  115.         hex       = 0x0040, // hexadecimal conversion
  116.         showbase  = 0x0080, // use base indicator on output
  117.         showpoint = 0x0100, // force decimal point (floating output)
  118.         uppercase = 0x0200, // upper-case hex output
  119.         showpos   = 0x0400, // add '+' to positive integers
  120.         scientific= 0x0800, // use 1.2345E2 floating notation
  121.         fixed     = 0x1000, // use 123.45 floating notation
  122.         unitbuf   = 0x2000, // flush all streams after insertion
  123.         stdio     = 0x4000, // flush stdout, stderr after insertion
  124.         boolalpha = 0x8000  // insert/extract bools as text or numeric
  125.         };
  126.  
  127.     // constants for second parameter of seft()
  128. static  const long basefield;       // dec | oct | hex
  129. static  const long adjustfield;     // left | right | internal
  130. static  const long floatfield;      // scientific | fixed
  131.  
  132.     // constructor, destructor
  133.             _RTLENTRY ios(streambuf _FAR *);
  134. virtual     _RTLENTRY ~ios();
  135.  
  136.     // for reading/setting/clearing format flags
  137.     long    _RTLENTRY flags();
  138.     long    _RTLENTRY flags(long);
  139.     long    _RTLENTRY setf(long _setbits, long _field);
  140.     long    _RTLENTRY setf(long);
  141.     long    _RTLENTRY unsetf(long);
  142.  
  143.     // reading/setting field width
  144.     int     _RTLENTRY width();
  145.     int     _RTLENTRY width(int);
  146.  
  147.     // reading/setting padding character
  148.     char    _RTLENTRY fill();
  149.     char    _RTLENTRY fill(char);
  150.  
  151.     // reading/setting digits of floating precision
  152.     int     _RTLENTRY precision(int);
  153.     int     _RTLENTRY precision();
  154.  
  155.     // reading/setting ostream tied to this stream
  156.     ostream _FAR * _RTLENTRY tie(ostream _FAR *);
  157.     ostream _FAR * _RTLENTRY tie();
  158.  
  159.     // find out about current stream state
  160.     int     _RTLENTRY rdstate();       // return the stream state
  161.     int     _RTLENTRY eof();           // non-zero on end of file
  162.     int     _RTLENTRY fail();          // non-zero if an operation failed
  163.     int     _RTLENTRY bad();           // non-zero if error occurred
  164.     int     _RTLENTRY good();          // non-zero if no state bits set
  165.     void    _RTLENTRY clear(int = 0);  // set the stream state
  166.             _RTLENTRY operator void _FAR * (); // zero if state failed
  167.     int     _RTLENTRY operator! ();    // non-zero if state failed
  168.  
  169.     streambuf _FAR * _RTLENTRY rdbuf();        // get the assigned streambuf
  170.  
  171.     // for declaring additional flag bits and user words
  172. static long _RTLENTRY bitalloc();  // acquire a new flag bit, value returned
  173. static int  _RTLENTRY xalloc();    // acquire a new user word, index returned
  174.     long    _FAR & _RTLENTRY iword(int);  // return the nth user word as an int
  175.     void    _FAR * _FAR & _RTLENTRY pword(int);  // return the nth user word as a pointer
  176.  
  177. static void _RTLENTRY sync_with_stdio();
  178.  
  179.     // obsolete, for streams 1.2 compatibility
  180.     int     _RTLENTRY skip(int);
  181.  
  182.     int     delbuf() {return x_delbuf;}
  183.     int     delbuf(int _new) {int _x=x_delbuf;x_delbuf=_new;return _x;}
  184. protected:
  185.     // additional state flags for ispecial and ospecial
  186.     enum { skipping = 0x100, tied = 0x200 };
  187.  
  188.     streambuf _FAR * bp;    // the associated streambuf
  189.     ostream _FAR * x_tie;   // the tied ostream, if any
  190.     int     state;          // status bits
  191.     int     ispecial;       // istream status bits  ***
  192.     int     ospecial;       // ostream status bits  ***
  193.     long    x_flags;        // formatting flag bits
  194.     int     x_precision;    // floating-point precision on output
  195.     int     x_width;        // field width on output
  196.     int     x_fill;         // padding character on output
  197.     int     isfx_special;   // unused       ***
  198.     int     osfx_special;   // unused       ***
  199.     int     x_delbuf;       // unused       ***
  200.     int     assign_private; // unused       ***
  201. /*
  202.  * The data members marked with *** above are not documented in the AT&T
  203.  * release of streams, so we cannot guarantee compatibility with any
  204.  * other streams release in the use or values of these data members.
  205.  * If you can document any expected behavior of these data members, we
  206.  * will try to adjust our implementation accordingly.
  207.  */
  208.  
  209.             _RTLENTRY ios();       // null constructor, does not initialize
  210.  
  211.     void    _RTLENTRY init(streambuf _FAR *);  // the actual initialization
  212.  
  213.     void    _RTLENTRY setstate(int);       // set all status bits
  214.  
  215. static  void _RTLENTRY (*stdioflush)();
  216.  
  217. private:
  218.     // for extra flag bits and user words
  219. static  long    nextbit;
  220. static  int usercount;
  221.     union ios_user_union _FAR *userwords;
  222.     int     nwords;
  223.     void    _RTLENTRY usersize(int);
  224.  
  225.     // these declarations prevent automatic copying of an ios
  226.             _RTLENTRY ios(ios _FAR &);           // declared but not defined
  227.     void    _RTLENTRY operator= (ios _FAR &);    // declared but not defined
  228.  
  229. };
  230. inline streambuf _FAR * _RTLENTRY ios::rdbuf() { r